export default {
  title: '数据字典',
  type: 'table',
  permission: '/system/dict/list',
  config: {
    dataUrl: '/system/dict/list',

    filter: {
      controls: [
        {
          key: 'nameContains',
          label: '名称',
          type: 'text'
        }
      ]
    },

    columns: [
      {
        key: 'createdDate',
        title: '创建时间',
        type: 'datetime',
        sorter: true,
        defaultSortOrder: 'descend'
      },
      {
        key: 'name',
        title: '名称'
      },
      {
        key: 'description',
        title: '描述'
      },
    ],

    actions: [
      {
        key: 'create',
        text: '添加字典',
        icon: 'plus',
        type: 'form',
        permission: '/system/dict/create',
        config: {
          color: 'primary',
          title: '添加字典',
          submitUrl: '/system/dict/create',
          submitText: '确认添加',
          submitSuccessMessage: '添加成功',
          controls: [
            {
              key: 'name',
              label: '名称',
              type: 'text',
              required: true,
              config: {
                rules: [
                  {max: 30, message: '最多输入 30 字符'}
                ]
              }
            },
            {
              key: 'description',
              label: '描述',
              type: 'textarea',
              config: {
                rules: [
                  {max: 200, message: '只能输入 200 个字符'}
                ]
              }
            },
          ]
        }
      }
    ],

    sorter: {
      sortableColumns: ['createdDate'],
      defaultSort: '-createdDate',
    },

    rowActions: [
      {
        key: 'edit',
        text: '修改',
        type: 'form',
        icon: 'edit',
        permission: '/system/dict/edit',
        config: {
          color: 'primary',
          title: '修改字典',
          initUrl: '/system/dict/edit/get',
          submitUrl: '/system/dict/edit',
          submitText: '确认修改',
          submitSuccessMessage: '修改成功',
          controls: [
            {
              key: 'name',
              label: '字典名',
              type: 'text',
              required: true,
              config: {
                rules: [
                  {min: 1, max: 30, message: '只能输入1-30个字符'}
                ]
              }
            },
            {
              key: 'description',
              label: '描述',
              type: 'textarea',
              config: {
                rules: [
                  {min: 1, max: 500, message: '只能输入1-500个字符'}
                ]
              }
            },
          ]
        }
      },
      {
        key: 'dictItems',
        text: '字典项',
        type: 'table',
        permission: '/system/dict-item/list',
        config: {
          color: 'primary',
          title: '字典项',
          dataUrl: '/system/dict-item/list',
          extraParamMapping: {
            filter: {
              id: 'dictIdIs'
            },
            action: {
              id: 'dictId'
            }
          },
          filter: {
            controls: [
              {
                key: 'valueContains',
                label: '值',
                type: 'text'
              }
            ]
          },

          columns: [
            {
              key: 'createdDate',
              title: '创建时间',
              type: 'datetime'
            },
            {
              key: 'value',
              title: '值'
            }
          ],

          actions: [
            {
              key: 'create',
              text: '添加字典项',
              icon: 'plus',
              type: 'form',
              permission: '/system/dict-item/create',
              config: {
                color: 'primary',
                title: '添加字典项',
                submitUrl: '/system/dict-item/create',
                submitText: '确认添加',
                submitSuccessMessage: '添加成功',
                controls: [
                  {
                    key: 'value',
                    label: '值',
                    type: 'text',
                    required: true,
                    config: {
                      rules: [
                        {max: 30, message: '最多输入 30 字符'}
                      ]
                    }
                  }
                ]
              }
            }
          ],

          sorter: {
            sortableColumns: ['createdDate'],
            defaultSort: '-createdDate',
          },

          rowActions: [
            {
              key: 'edit',
              text: '修改',
              type: 'form',
              icon: 'edit',
              permission: '/system/dict-item/edit',
              config: {
                color: 'primary',
                title: '修改字典',
                initUrl: '/system/dict-item/edit/get',
                submitUrl: '/system/dict-item/edit',
                submitText: '确认修改',
                submitSuccessMessage: '修改成功',
                controls: [
                  {
                    key: 'value',
                    label: '值',
                    type: 'text',
                    required: true,
                    config: {
                      rules: [
                        {max: 30, message: '最多输入 30 个字符'}
                      ]
                    }
                  }
                ]
              }
            }
          ]
        }
      },
    ]
  }
}

